package routers

import (
	"gin_study_blog/api"
	"gin_study_blog/middleware"
	"github.com/gin-contrib/sessions"
	"github.com/gin-contrib/sessions/cookie"
)

func (r RouterGroup) UserRouter() {
	userApi := api.ApiGroupApp.UserApi
	//配置session中间件
	//创建一个基于cookie的存储引擎，secret参数是用于加密的秘钥，可以自定义
	store := cookie.NewStore([]byte("007OFI55DB7710OK"))
	//创建一个cookie存储引擎的中间件
	r.Use(sessions.Sessions("blog_ycc", store))
	// 邮箱登录
	r.POST("email_login", userApi.EmailLoginView)
	// 用户列表
	r.GET("users", middleware.JwtUserAuth(), userApi.UserListView)
	r.PUT("user_role", middleware.JwtAdminAuth(), userApi.UserModifyRoleView)
	r.PUT("user_password", middleware.JwtUserAuth(), userApi.UserModifyPassword)
	r.POST("user_logout", middleware.JwtUserAuth(), userApi.UserLogout)
	r.DELETE("user_delete", middleware.JwtAdminAuth(), userApi.UserDeleteView)
	r.POST("bind_email", middleware.JwtUserAuth(), userApi.UserBindEmailView)
	r.POST("login", userApi.QqLoginView)
	r.POST("user_create", middleware.JwtAdminAuth(), userApi.UserCreateView)
}
